﻿
/*
 * PsTFS is a set of PowerShell commands to manage and use Team Foundation Server. PowerShell 
 * effectiveness is combined with the power of TFS API to maximizes TFS capabilities.
 * 
 * Creator : Choulant Noham
 * Mail : choulant@gmail.com
 * Blog : http://choulant.blogspot.com
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation;

namespace PsTFS.Objects.Methodes
{
    /// <summary>
    /// Extention de méthode
    /// </summary>
    public static class Methode_Extention
    {
        /// <summary>
        /// Ajout de la méthode sur le workitem pour avoir facilement tous les changesets
        /// </summary>
        /// <param name="wi"></param>
        /// <returns></returns>
        public static List<Changeset> ListChangeset(this WorkItem wi) 
        {  
            VersionControlServer vcs = Methode_Service.VCS();
            List<Changeset> associatedChangesets = new List<Changeset>();
            foreach (Link link in wi.Links)
            {
                ExternalLink extLink = link as ExternalLink;
                if (extLink != null)
                {
                    ArtifactId artifact = LinkingUtilities.DecodeUri(extLink.LinkedArtifactUri);
                    if (String.Equals(artifact.ArtifactType, "Changeset", StringComparison.Ordinal))
                    {
                        // Convert the artifact URI to Changeset object.
                        associatedChangesets.Add(vcs.ArtifactProvider.GetChangeset(new Uri(extLink.LinkedArtifactUri)));
                    }
                }
            }

            return associatedChangesets;
        }
    }
}
